import sys
import os
from   os.path import abspath, dirname
sys.path.insert(0,abspath(dirname(__file__)))
import tkinter
from   tkinter import * 
import Fun
from broker import MQTTClient
#import simulation
#import console
#from broker import initialize_mqtt_client
uiName="Project1"
ElementBGArray={}
ElementBGArray_Resize={}
ElementBGArray_IM={}

global mqtt_client
i=0
#Form 'Form_1's Event :Load
def Form_1_onLoad(uiName):
    pass

#Button 'Button_1' 's Command Event :
def Button_1_onCommand(uiName,widgetName):
    mqtt_broker=Fun.GetText(uiName,'Entry_1')
    global mqtt_client
    mqtt_client=MQTTClient(mqtt_broker)
    mqtt_client.connect()
    if mqtt_client.connected:
        Fun.SetTextColor(uiName,'Label_3',RGBColor='#DA4453')
        Fun.SetTextColor(uiName,'Label_5',RGBColor='#000000')
    else:
        Fun.SetTextColor(uiName,'Label_2',RGBColor='#DA4453')
        Fun.SetTextColor(uiName,'Label_5',RGBColor='#000000')
    pass
#Button 'Button_2' 's Command Event :
def Button_2_onCommand(uiName,widgetName):  
    
    import simulation  
    NoteBook=Fun.GetElement(uiName,'NoteBook_1') 
    Fun.AddPage(uiName,'NoteBook_1',text="车辆",iconFile="",targetUIName='simulation') 
    pass
#Button 'Button_3' 's Command Event :
def Button_3_onCommand(uiName,widgetName):
    pageIndex = Fun.GetSelectedPageIndex(uiName,'NoteBook_1')
    Fun.DelPage(uiName,'NoteBook_1',index=pageIndex)
    pass
#Button 'Button_4' 's Command Event :
def Button_4_onCommand(uiName,widgetName):
    Fun.SetVisible(uiName,'Frame_2',True)
    Fun.SetVisible(uiName,'Frame_3',False)
    Fun.SetVisible(uiName,'Frame_4',True)
    Fun.SetBGColor(uiName,'Button_4',RGBColor='#DA4453')
    Fun.SetTextColor(uiName,'Button_4',RGBColor='#FFFFFF')
    Fun.SetBGColor(uiName,'Button_5',RGBColor='#FFFFFF')
    Fun.SetTextColor(uiName,'Button_5',RGBColor='#000000')
    
    pass
#Button 'Button_5' 's Command Event :
def Button_5_onCommand(uiName,widgetName): 
    import console
    Fun.SetVisible(uiName,'Frame_2',False)
    Fun.SetVisible(uiName,'Frame_3',True)
    Fun.SetVisible(uiName,'Frame_4',False)
    Fun.SetBGColor(uiName,'Button_4',RGBColor='#FFFFFF')
    Fun.SetTextColor(uiName,'Button_4',RGBColor='#000000')
    Fun.SetBGColor(uiName,'Button_5',RGBColor='#DA4453')
    Fun.SetTextColor(uiName,'Button_5',RGBColor='#FFFFFF')
    Fun.LoadUIDialog(uiName,'Frame_3','console',None)
    pass
#Button 'Button_6' 's Command Event :
def Button_6_onCommand(uiName,widgetName):
    import webbrowser
    webbrowser.open('http://49.235.117.58/tcs_map/')
    pass
